import BaseSelect from '../../BaseSelect/index.vue'
import {AbstractComponent} from "/@/components/Base/BaseEditTable/component/AbstractComponent";
import {isRef, nextTick} from "vue";

export class Select extends AbstractComponent {
    public async getFocus(vRef: any) {
        await nextTick()
        let timer = setTimeout(() => {
            vRef.value.$el.click()
            clearTimeout(timer);
        }, 1);
    }

    private value
    private options = []
    private props = {
        label: 'label',
        value: 'value'
    }

    public setProperties(value, obj) {
        this.value = value
        this.options = isRef(obj.options) ? obj.options.value : obj.options
        if (obj.props) {
            this.props = obj.props
        }
    }


    public getComponent() {
        return BaseSelect
    }

    public formatLabel(): string {
        let item = this.options.find(res => res[this.props.value] == this.value)
        if (item) {
            return item[this.props.label]
        }
        return ''
    }

    public whetherFormat(): boolean {
        return true;
    }
}